From 1f1b3b675f1a823bd7293a15e9047c8a420600d8 Mon Sep 17 00:00:00 2001 From: robertlipe Date: Sun, 12 Oct 2014 02:17:07 +0000 Subject: [PATCH] Minort QString-ificaion of google.cc --- gpsbabel/google.cc | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/gpsbabel/google.cc b/gpsbabel/google.cc index cd196b283..1cd22aaa6 100644 --- a/gpsbabel/google.cc +++ b/gpsbabel/google.cc @@ -25,7 +25,7 @@ static char* encoded_points = NULL; static char* encoded_levels = NULL; -static char* script = NULL; +static QString script; static route_head** routehead; static int* routecount; static short_handle desc_handle; @@ -58,11 +58,7 @@ xg_tag_mapping google_map[] = { void goog_script(xg_string args, const QXmlStreamAttributes*) { - if (script) { - script = xstrappend(script, CSTRc(args)); - } else { - script = xstrdup(args); - } + script += args; } @@ -86,7 +82,7 @@ void goog_levels(xg_string args, const QXmlStreamAttributes*) } static char goog_segname[7]; -static char* goog_realname = NULL; +static QString goog_realname; static int goog_segroute = 0; /* @@ -152,24 +148,17 @@ void goog_td_s(xg_string args, const QXmlStreamAttributes* attrv) void goog_td_b(xg_string args, const QXmlStreamAttributes*) { if (goog_segname[0] == '\\' && !strchr(CSTRc(args), '\xa0')) { - if (goog_realname) { - xfree(goog_realname); - goog_realname = NULL; - } - goog_realname = (char*) xmalloc(strlen(CSTRc(args))+1); - strcpy(goog_realname, CSTRc(args)); + goog_realname = args; } } + void goog_td_e(xg_string args, const QXmlStreamAttributes*) { - if (goog_segname[0] == '\\' && goog_realname) { + if (goog_segname[0] == '\\' && !goog_realname.isEmpty()) { goog_segment(goog_realname, NULL/*unused*/); } goog_segname[0] = '\0'; - if (goog_realname) { - xfree(goog_realname); - goog_realname = NULL; - } + goog_realname.clear(); } static long decode_goog64(char** str) @@ -311,10 +300,11 @@ google_read(void) xfree(encoded_levels); encoded_levels = NULL; } - if (script) { - char* xml = strchr(script, '\''); - char* dict = strstr(script, "({"); - + if (!script.isEmpty()) { + // TODO: rethink with Qt to make this less dependent on strchr... + char* s = xstrdup(script); + char* xml = strchr(s, '\''); + char* dict = strstr(s, "({"); char* end = NULL; if (xml && (!dict || (xml < dict))) { @@ -519,10 +509,10 @@ google_read(void) } } } - xfree(script); + script.clear(); xfree(routehead); xfree(routecount); - script = NULL; + xfree(s); } /* -- 2.30.2